package com.hl.wuyeguanliIDEA.service.impl;
import com.hl.wuyeguanliIDEA.mapper.UserYZMapper;
import com.hl.wuyeguanliIDEA.pojo.UserYZ;
import com.hl.wuyeguanliIDEA.service.UserYZService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserYZServiceImpl implements UserYZService {
    @Autowired
    private UserYZMapper userYZMapper;

    @Override
    public UserYZ login(String phone, String password) {
        UserYZ user = userYZMapper.findByPhone(phone);
        if (user != null && user.getPassword().equals(password)) {
            return user;
        }
        return null;
    }

    @Override
    public UserYZ getUserInfo(String phone) {
        return userYZMapper.findByPhone(phone);
    }

    @Override
    public boolean changePassword(String phone, String oldPassword, String newPassword) {
        UserYZ user = userYZMapper.findByPhone(phone);
        if (user != null && user.getPassword().equals(oldPassword)) {
            int result = userYZMapper.updatePassword(phone, newPassword);
            return result > 0;
        }
        return false;
    }
}